<template>
	<div :class="curClassName" :style="curStyle" @click="handleClick">
		<img v-if="imgUrl" :src="imgUrl" />
		<i v-else :class="imageClass ? imageClass : ''"></i>
	</div>
</template>
<script setup lang="ts">
import { IEvent } from '@/core';
import { RawItemImageProps } from './rawitem-image';
const props = defineProps(RawItemImageProps);
interface RawItemImageEmit {
	(name: 'component-action', value: IEvent<string>): void;
}
const emit = defineEmits<RawItemImageEmit>();

/**
 * 项名称
 *
 * @memberof RawItemImage
 */
const itemName = computed(() => {
	return props.index || props.index === 0
		? `${props.name}_${props.index}`
		: props.name;
});

/**
 * 当前容器样式
 *
 * @memberof RawItemImage
 */
const curStyle = computed(() => {
	const layoutModel = props.layoutModelDetails[itemName.value];
	if (layoutModel) {
		return layoutModel.getElementStyle();
	}
});

/**
 * 类名
 *
 * @memberof RawItemImage
 */
const curClassName = computed(() => {
	const layoutModel = props.layoutModelDetails[itemName.value];
	const classNames = {
		'app-rawitem-image': true
	};
	if (layoutModel) {
		Object.assign(classNames, layoutModel.getClassNames());
	}
	return classNames;
});

/**
 * 处理点击事件
 *
 * @memberof RawItemImage
 */
const handleClick = ($event:any) => {
	emit('component-action', {
		name: props.name,
		action: 'panelItemClick',
		data: $event,
	});
}
</script>
